package cn.rokhdelar.umbrsapi.management.service;

import cn.rokhdelar.umbrsapi.management.entity.SysDepartment;
import cn.rokhdelar.umbrsapi.management.repository.SysDepartmentRepo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

@Service
public class SysDepartmentService {
    private final SysDepartmentRepo sysDepartmentRepo;

    public SysDepartmentService(SysDepartmentRepo sysDepartmentRepo) {
        this.sysDepartmentRepo = sysDepartmentRepo;
    }

    public Page<SysDepartment> list(String name, Pageable pageable) {
        return sysDepartmentRepo.findAllByNameContaining(name, pageable);
    }

    public SysDepartment get(Long id) {
        return sysDepartmentRepo.findById(id).orElse(null);
    }

    public SysDepartment save(SysDepartment sysDepartment) {
        return sysDepartmentRepo.save(sysDepartment);
    }

    public void delete(Long id) {
        sysDepartmentRepo.deleteById(id);
    }
}
